package com.lky.marshall.mallcart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by
 * autor : Marshall lky
 * datetime: 2021/6/1 10:03
 * 整个购物车
 */
@Data
public class CartVo {

    private List<CartItemVo> cartItems;
    private Integer count;
    private Integer countType;
    private BigDecimal totalAmount;
    private BigDecimal reduce = new BigDecimal("0");

    public List<CartItemVo> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItemVo> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getCount(List<CartItemVo> cartItems) {
        int count = 0;
        if (cartItems !=null&& cartItems.size()>0){
            for (CartItemVo cartItem : cartItems) {
                count+=cartItem.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        int count = 0;
        if (cartItems !=null&& cartItems.size()>0){
            for (CartItemVo cartItem : cartItems) {
                count+=1;
            }
        }
        return count;
    }


    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        if (cartItems !=null&& cartItems.size()>0){
            for (CartItemVo cartItem : cartItems) {
                if (cartItem.getCheck()) {
                    amount = amount.add(cartItem.getTotalPrice());
                }
            }
        }
        amount = amount.subtract(getReduce());
        return amount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
